package xps.and.uudaijia.userclient.view.activity;

import android.widget.ImageView;
import android.widget.TextView;

import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import nucleus.factory.RequiresPresenter;
import xps.and.uudaijia.userclient.R;
import xps.and.uudaijia.userclient.presenter.OfflineMapPresenter;
import xps.and.uudaijia.userclient.view.base.BaseActivity;

@RequiresPresenter(OfflineMapPresenter.class)
public class DownloadOfflineMapActivity extends BaseActivity<OfflineMapPresenter> {
    @BindView(R.id.actionbar_iv_back)
    ImageView actionbarIvBack;
    @BindView(R.id.actionbar_tv_title)
    TextView actionbarTvTitle;
    @BindView(R.id.actionbar_al)
    AutoRelativeLayout actionbar_al;
    @BindView(R.id.offLineState)
    TextView offLineState;

    @Override
    protected int getLayout() {
        return R.layout.activity_offlinemap;
    }

    @Override
    protected void setData() {

    }

    @Override
    protected void init() {
        ButterKnife.bind(this);
        if (getPresenter().getOfflineState()) {
            offLineState.setText("已缓存");
            addPlusButton("已缓存");
        } else {
            offLineState.setText("未缓存");
            addPlusButton("未缓存");
        }
    }

    void addPlusButton(String stateStr) {
        TextView imageView = new TextView(this);
        imageView.setText(stateStr);
        imageView.setOnClickListener((v) -> {
            if(stateStr.equals("未缓存")){
                getPresenter().start(this);
            }else {
                getPresenter().removeOfflineData();
            }
        });

        AutoRelativeLayout.LayoutParams layoutParams = new AutoRelativeLayout.LayoutParams(AutoRelativeLayout.LayoutParams.WRAP_CONTENT, AutoRelativeLayout.LayoutParams.MATCH_PARENT);
        layoutParams.addRule(AutoRelativeLayout.ALIGN_PARENT_RIGHT);
        layoutParams.setMargins(40, 40, 25, 40);
        actionbar_al.addView(imageView, layoutParams);
    }

}
